/**
 * Created by xiamengyu on 7/11/16.
 */
var _ = require('lodash');
var separator = ":";
var ap = Array.prototype;
module.exports.type = {
    'normal': 'normal',
    'chayi': 'chayi',
    'final': 'final',
    'abnormal': 'abnormal',
    'done': 'done',
    'tagabnormal': 'tagabnormal',
    'twicenormal': 'twicenormal',
    //抽样复评相关key
    'sample':'sample',
    'sampled':'sampled',
    'unsampled':'unsampled',
    'unsampledNormal':'unsampledNormal'
};

module.exports.upload = {
    'index' : 'index',
    'keguanti' : 'keguanti',
    'zhuguanti': 'zhuguanti',
    'monitor' : 'monitor',
    'abjuan' : 'abjuan',
    'option' : 'option',
    'absence' : 'absence',
    'cheat': 'cheat'
};

module.exports.separator = separator;

module.exports.keyFnName = keyFnName = function(prefix) {
    return prefix + 'Key';
};

module.exports.doingKeyFnName = doingKeyFnName = function(prefix) {
    return _.camelCase('doing ' + prefix + 'PoolKey')
};

module.exports.poolKeyFnName = poolKeyFnName = function(prefix) {
    return prefix + 'PoolKey';
};

module.exports.uploadKeyFnName = uploadKeyFnName = function (prefix) {
    return prefix + 'UploadKey';
};

module.exports.xuanzuoKeyFnName = xuanzuoKeyFnName = function (prefix) {
    return _.camelCase('xuanzuo ' + prefix + 'UploadKey')
};

module.exports.banjiKeyFnName = banjiKeyFnName = function (prefix) {
    return _.camelCase('banji ' + prefix + 'UploadKey')
};

module.exports.join = function(args) {
    if (!_.isArray(args)) {
        args = ap.slice.call(arguments);
    }
    return args.join(separator);
};


//typeKey
_.each(['AI','stus', 'reviewed', 'reviews', 'history', 'result', 'monitor', 'stuBlock', 'lock', 'filter', 'doingTime', "abreviewers", 'alloted', 'twice', 'banjiCount'], function(prefix) {
    module.exports[keyFnName(prefix)] = function() {
        var args = ap.slice.call(arguments), params = [];
        params.push(args.shift());//paperId
        params.push(prefix);
        return params.concat(args).join(separator);
    }
});


_.each(Object.keys(module.exports.type), function(prefix) {
    //typePoolKey
    module.exports[poolKeyFnName(prefix)] = function() {
        var args = ap.slice.call(arguments), params = [];
        params.push(args.shift());//paperId
        params.push('pool');
        params.push(args.shift());
        params.push(prefix);
        return params.concat(args).join(separator);
    };
    //doingTypePoolKey
    module.exports[doingKeyFnName(prefix)] = function() {
        var args = ap.slice.call(arguments), params = [];
        params.push(args.shift());//paperId
        params.push('pool');
        params.push(args.shift());
        params.push('doing');
        args.push(prefix);
        return params.concat(args).join(separator);
    }
});

_.each(Object.keys(module.exports.upload), function(type) {
    //uploadUploadKey
    module.exports[uploadKeyFnName(type)] = function () {
        var args = ap.slice.call(arguments), params = [];
        params.push(args.shift());//paperId
        params.push('uploads');
        params.push(type);
        return params.join(separator);
    }
    //xuanzuoUploadUploadKey
    module.exports[xuanzuoKeyFnName(type)] = function () {
        var args = ap.slice.call(arguments), params = [];
        params.push(args.shift());//paperId
        params.push('uploads');
        params.push('xuanzuo');
        params.push(type);
        return params.join(separator);
    }
    //banjiUploadUploadKey
    module.exports[banjiKeyFnName(type)] = function () {
        var args = ap.slice.call(arguments), params = [];
        params.push(args.shift());//paperId
        params.push('uploads');
        params.push('banji');
        params.push(type);
        return params.join(separator);
    }
});
